﻿@model Orchard.ArchiveLater.ViewModels.ArchiveLaterViewModel
@using System.Web.Mvc.Html;
@{
    Style.Require("ArchiveLater_DatePicker");
}

<fieldset class="archive-later-datetime">
    <legend>@T("Archive Settings")</legend>
    <div>
        @Html.CheckBox("ArchiveLater", Model.ScheduledArchiveUtc.HasValue, new { id = ViewData.TemplateInfo.GetFullHtmlFieldId("Command_ArchiveLater") })
        <label class="forcheckbox" for="@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_ArchiveLater")">@T("Archive Later")</label>
    </div>
    <div>
        <label class="forpicker" for="@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledArchiveDate")">@T("Date")</label>
        @Html.EditorFor(m => m.ScheduledArchiveDate)
        <label class="forpicker" for="@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledArchiveTime")">@T("Time")</label>
        @Html.EditorFor(m => m.ScheduledArchiveTime)
    </div>
</fieldset>
@using(Script.Foot()) {
    
    @* generates the localization script *@
    @Display(New.DatePickerLocalization())
    @Display(New.TimePickerLocalization())

<script type="text/javascript">    
//<![CDATA[
    $(function () {
        //todo: (heskew) make a plugin
        $("label.forpicker").each(function () {
            var $this = $(this);
            var pickerInput = $("#" + $this.attr("for"));
            pickerInput.data("hint", $this.text());
            if (!pickerInput.val()) {
                pickerInput.addClass("hinted")
            .val(pickerInput.data("hint"))
            .focus(function () { var $this = $(this); if ($this.val() == $this.data("hint")) { $this.removeClass("hinted").val("") } })
            .blur(function () { var $this = $(this); setTimeout(function () { if (!$this.val()) { $this.addClass("hinted").val($this.data("hint")) } }, 300) });
            }
        });
        $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledArchiveDate")').datepicker({ showAnim: "" }).focus(function () { $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_ArchiveLater")').attr("checked", "checked") });
        $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledArchiveTime")').timepicker({ stepMinute: 5 }).focus(function () { $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_ArchiveLater")').attr("checked", "checked") });
    })
//]]>
</script>
}